1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module soup.CookieJar; 26 27 private import glib.ConstructionException; 28 private import glib.ListSG; 29 private import glib.Str; 30 private import glib.c.functions; 31 private import gobject.ObjectG; 32 private import gobject.Signals; 33 private import soup.Cookie; 34 private import soup.SessionFeatureIF; 35 private import soup.SessionFeatureT; 36 private import soup.URI; 37 private import soup.c.functions; 38 public import soup.c.types; 39 private import std.algorithm; 40 41 42 /** */ 43 public class CookieJar : ObjectG, SessionFeatureIF 44 { 45 /** the main Gtk struct */ 46 protected SoupCookieJar* soupCookieJar; 47 48 /** Get the main Gtk struct */ 49 public SoupCookieJar* getCookieJarStruct(bool transferOwnership = false) 50 { 51 if (transferOwnership) 52 ownedRef = false; 53 return soupCookieJar; 54 } 55 56 /** the main Gtk struct as a void* */ 57 protected override void* getStruct() 58 { 59 return cast(void*)soupCookieJar; 60 } 61 62 /** 63 * Sets our main struct and passes it to the parent class. 64 */ 65 public this (SoupCookieJar* soupCookieJar, bool ownedRef = false) 66 { 67 this.soupCookieJar = soupCookieJar; 68 super(cast(GObject*)soupCookieJar, ownedRef); 69 } 70 71 // add the SessionFeature capabilities 72 mixin SessionFeatureT!(SoupCookieJar); 73 74 75 /** */ 76 public static GType getType() 77 { 78 return soup_cookie_jar_get_type(); 79 } 80 81 /** 82 * Creates a new #SoupCookieJar. The base #SoupCookieJar class does 83 * not support persistent storage of cookies; use a subclass for that. 84 * 85 * Returns: a new #SoupCookieJar 86 * 87 * Since: 2.24 88 * 89 * Throws: ConstructionException GTK+ fails to create the object. 90 */ 91 public this() 92 { 93 auto __p = soup_cookie_jar_new(); 94 95 if(__p is null) 96 { 97 throw new ConstructionException("null returned by new"); 98 } 99 100 this(cast(SoupCookieJar*) __p, true); 101 } 102 103 /** 104 * Adds @cookie to @jar, emitting the 'changed' signal if we are modifying 105 * an existing cookie or adding a valid new cookie ('valid' means 106 * that the cookie's expire date is not in the past). 107 * 108 * @cookie will be 'stolen' by the jar, so don't free it afterwards. 109 * 110 * Params: 111 * cookie = a #SoupCookie 112 * 113 * Since: 2.26 114 */ 115 public void addCookie(Cookie cookie) 116 { 117 soup_cookie_jar_add_cookie(soupCookieJar, (cookie is null) ? null : cookie.getCookieStruct(true)); 118 } 119 120 /** 121 * Adds @cookie to @jar, emitting the 'changed' signal if we are modifying 122 * an existing cookie or adding a valid new cookie ('valid' means 123 * that the cookie's expire date is not in the past). 124 * 125 * @first_party will be used to reject cookies coming from third party 126 * resources in case such a security policy is set in the @jar. 127 * 128 * @uri will be used to reject setting or overwriting secure cookies 129 * from insecure origins. %NULL is treated as secure. 130 * 131 * @cookie will be 'stolen' by the jar, so don't free it afterwards. 132 * 133 * Params: 134 * cookie = a #SoupCookie 135 * uri = the URI setting the cookie 136 * firstParty = the URI for the main document 137 * 138 * Since: 2.68 139 */ 140 public void addCookieFull(Cookie cookie, URI uri, URI firstParty) 141 { 142 soup_cookie_jar_add_cookie_full(soupCookieJar, (cookie is null) ? null : cookie.getCookieStruct(true), (uri is null) ? null : uri.getURIStruct(), (firstParty is null) ? null : firstParty.getURIStruct()); 143 } 144 145 /** 146 * Adds @cookie to @jar, emitting the 'changed' signal if we are modifying 147 * an existing cookie or adding a valid new cookie ('valid' means 148 * that the cookie's expire date is not in the past). 149 * 150 * @first_party will be used to reject cookies coming from third party 151 * resources in case such a security policy is set in the @jar. 152 * 153 * @cookie will be 'stolen' by the jar, so don't free it afterwards. 154 * 155 * For secure cookies to work properly you may want to use 156 * soup_cookie_jar_add_cookie_full(). 157 * 158 * Params: 159 * firstParty = the URI for the main document 160 * cookie = a #SoupCookie 161 * 162 * Since: 2.40 163 */ 164 public void addCookieWithFirstParty(URI firstParty, Cookie cookie) 165 { 166 soup_cookie_jar_add_cookie_with_first_party(soupCookieJar, (firstParty is null) ? null : firstParty.getURIStruct(), (cookie is null) ? null : cookie.getCookieStruct(true)); 167 } 168 169 /** 170 * Constructs a #GSList with every cookie inside the @jar. 171 * The cookies in the list are a copy of the original, so 172 * you have to free them when you are done with them. 173 * 174 * Returns: a #GSList 175 * with all the cookies in the @jar. 176 * 177 * Since: 2.26 178 */ 179 public ListSG allCookies() 180 { 181 auto __p = soup_cookie_jar_all_cookies(soupCookieJar); 182 183 if(__p is null) 184 { 185 return null; 186 } 187 188 return new ListSG(cast(GSList*) __p, true); 189 } 190 191 /** 192 * Deletes @cookie from @jar, emitting the 'changed' signal. 193 * 194 * Params: 195 * cookie = a #SoupCookie 196 * 197 * Since: 2.26 198 */ 199 public void deleteCookie(Cookie cookie) 200 { 201 soup_cookie_jar_delete_cookie(soupCookieJar, (cookie is null) ? null : cookie.getCookieStruct()); 202 } 203 204 /** 205 * Gets @jar's #SoupCookieJarAcceptPolicy 206 * 207 * Returns: the #SoupCookieJarAcceptPolicy set in the @jar 208 * 209 * Since: 2.30 210 */ 211 public SoupCookieJarAcceptPolicy getAcceptPolicy() 212 { 213 return soup_cookie_jar_get_accept_policy(soupCookieJar); 214 } 215 216 /** 217 * Retrieves the list of cookies that would be sent with a request to @uri 218 * as a #GSList of #SoupCookie objects. 219 * 220 * If @for_http is %TRUE, the return value will include cookies marked 221 * "HttpOnly" (that is, cookies that the server wishes to keep hidden 222 * from client-side scripting operations such as the JavaScript 223 * document.cookies property). Since #SoupCookieJar sets the Cookie 224 * header itself when making the actual HTTP request, you should 225 * almost certainly be setting @for_http to %FALSE if you are calling 226 * this. 227 * 228 * Params: 229 * uri = a #SoupURI 230 * forHttp = whether or not the return value is being passed directly 231 * to an HTTP operation 232 * 233 * Returns: a #GSList 234 * with the cookies in the @jar that would be sent with a request to @uri. 235 * 236 * Since: 2.40 237 */ 238 public ListSG getCookieList(URI uri, bool forHttp) 239 { 240 auto __p = soup_cookie_jar_get_cookie_list(soupCookieJar, (uri is null) ? null : uri.getURIStruct(), forHttp); 241 242 if(__p is null) 243 { 244 return null; 245 } 246 247 return new ListSG(cast(GSList*) __p, true); 248 } 249 250 /** 251 * This is an extended version of soup_cookie_jar_get_cookie_list() that 252 * provides more information required to use SameSite cookies. See the 253 * [SameSite cookies spec](https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00) 254 * for more detailed information. 255 * 256 * Params: 257 * uri = a #SoupURI 258 * topLevel = a #SoupURI for the top level document 259 * siteForCookies = a #SoupURI indicating the origin to get cookies for 260 * forHttp = whether or not the return value is being passed directly 261 * to an HTTP operation 262 * isSafeMethod = if the HTTP method is safe, as defined by RFC 7231, ignored when @for_http is %FALSE 263 * isTopLevelNavigation = whether or not the HTTP request is part of 264 * top level navigation 265 * 266 * Returns: a #GSList 267 * with the cookies in the @jar that would be sent with a request to @uri. 268 * 269 * Since: 2.70 270 */ 271 public ListSG getCookieListWithSameSiteInfo(URI uri, URI topLevel, URI siteForCookies, bool forHttp, bool isSafeMethod, bool isTopLevelNavigation) 272 { 273 auto __p = soup_cookie_jar_get_cookie_list_with_same_site_info(soupCookieJar, (uri is null) ? null : uri.getURIStruct(), (topLevel is null) ? null : topLevel.getURIStruct(), (siteForCookies is null) ? null : siteForCookies.getURIStruct(), forHttp, isSafeMethod, isTopLevelNavigation); 274 275 if(__p is null) 276 { 277 return null; 278 } 279 280 return new ListSG(cast(GSList*) __p, true); 281 } 282 283 /** 284 * Retrieves (in Cookie-header form) the list of cookies that would 285 * be sent with a request to @uri. 286 * 287 * If @for_http is %TRUE, the return value will include cookies marked 288 * "HttpOnly" (that is, cookies that the server wishes to keep hidden 289 * from client-side scripting operations such as the JavaScript 290 * document.cookies property). Since #SoupCookieJar sets the Cookie 291 * header itself when making the actual HTTP request, you should 292 * almost certainly be setting @for_http to %FALSE if you are calling 293 * this. 294 * 295 * Params: 296 * uri = a #SoupURI 297 * forHttp = whether or not the return value is being passed directly 298 * to an HTTP operation 299 * 300 * Returns: the cookies, in string form, or %NULL if 301 * there are no cookies for @uri. 302 * 303 * Since: 2.24 304 */ 305 public string getCookies(URI uri, bool forHttp) 306 { 307 auto retStr = soup_cookie_jar_get_cookies(soupCookieJar, (uri is null) ? null : uri.getURIStruct(), forHttp); 308 309 scope(exit) Str.freeString(retStr); 310 return Str.toString(retStr); 311 } 312 313 /** 314 * Gets whether @jar stores cookies persistenly. 315 * 316 * Returns: %TRUE if @jar storage is persistent or %FALSE otherwise. 317 * 318 * Since: 2.40 319 */ 320 public bool isPersistent() 321 { 322 return soup_cookie_jar_is_persistent(soupCookieJar) != 0; 323 } 324 325 /** 326 * This function exists for backward compatibility, but does not do 327 * anything any more; cookie jars are saved automatically when they 328 * are changed. 329 * 330 * Deprecated: This is a no-op. 331 * 332 * Since: 2.24 333 */ 334 public void save() 335 { 336 soup_cookie_jar_save(soupCookieJar); 337 } 338 339 /** 340 * Sets @policy as the cookie acceptance policy for @jar. 341 * 342 * Params: 343 * policy = a #SoupCookieJarAcceptPolicy 344 * 345 * Since: 2.30 346 */ 347 public void setAcceptPolicy(SoupCookieJarAcceptPolicy policy) 348 { 349 soup_cookie_jar_set_accept_policy(soupCookieJar, policy); 350 } 351 352 /** 353 * Adds @cookie to @jar, exactly as though it had appeared in a 354 * Set-Cookie header returned from a request to @uri. 355 * 356 * Keep in mind that if the #SoupCookieJarAcceptPolicy set is either 357 * %SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY or 358 * %SOUP_COOKIE_JAR_ACCEPT_GRANDFATHERED_THIRD_PARTY you'll need to use 359 * soup_cookie_jar_set_cookie_with_first_party(), otherwise the jar 360 * will have no way of knowing if the cookie is being set by a third 361 * party or not. 362 * 363 * Params: 364 * uri = the URI setting the cookie 365 * cookie = the stringified cookie to set 366 * 367 * Since: 2.24 368 */ 369 public void setCookie(URI uri, string cookie) 370 { 371 soup_cookie_jar_set_cookie(soupCookieJar, (uri is null) ? null : uri.getURIStruct(), Str.toStringz(cookie)); 372 } 373 374 /** 375 * Adds @cookie to @jar, exactly as though it had appeared in a 376 * Set-Cookie header returned from a request to @uri. @first_party 377 * will be used to reject cookies coming from third party resources in 378 * case such a security policy is set in the @jar. 379 * 380 * Params: 381 * uri = the URI setting the cookie 382 * firstParty = the URI for the main document 383 * cookie = the stringified cookie to set 384 * 385 * Since: 2.30 386 */ 387 public void setCookieWithFirstParty(URI uri, URI firstParty, string cookie) 388 { 389 soup_cookie_jar_set_cookie_with_first_party(soupCookieJar, (uri is null) ? null : uri.getURIStruct(), (firstParty is null) ? null : firstParty.getURIStruct(), Str.toStringz(cookie)); 390 } 391 392 /** 393 * Emitted when @jar changes. If a cookie has been added, 394 * @new_cookie will contain the newly-added cookie and 395 * @old_cookie will be %NULL. If a cookie has been deleted, 396 * @old_cookie will contain the to-be-deleted cookie and 397 * @new_cookie will be %NULL. If a cookie has been changed, 398 * @old_cookie will contain its old value, and @new_cookie its 399 * new value. 400 * 401 * Params: 402 * oldCookie = the old #SoupCookie value 403 * newCookie = the new #SoupCookie value 404 */ 405 gulong addOnChanged(void delegate(Cookie, Cookie, CookieJar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 406 { 407 return Signals.connect(this, "changed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 408 } 409 }